package com.example.demo.dao;

import com.example.demo.domain.User;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Mapper
public interface UserDao {

    @Select("SELECT * FROM user WHERE name = #{name}")
    @Results(id = "user",value = {
            @Result(property = "loginCount",column = "login_count")
    })
    User findUserByName(@Param("name")String name);

    @Insert("INSERT INTO user(name,age,login_count) VALUES(#{user.name},#{user.age},1)")
    void saveUser(@Param("user")User user);

    @Select("SELECT * FROM user")
    @ResultMap("user")
    List<User> findAllUser();
}
